﻿using Common;
using Common.CustomException;
using NUnit.Framework;
using SpecFlowTfsLinker.Entities;
using SpecFlowTfsLinker.Test.Common;
using SpecFlowTfsLinker.Test.Resources;

namespace SpecFlowTfsLinker.Test.Builder
{
    [TestFixture]
    public class UserStoryBuilderTest : TestInitialization
    {
        [Test]
        public void CanCreateUserStoryWithParameter()
        {
            var us = UserStoryResources.Calculation.CompleteUserStory;
            Assert.IsNotNull(us);
            Assert.AreEqual(UserStoryResources.Calculation.Title, us.Title);
            Assert.AreEqual(UserStoryResources.Calculation.Description, us.Description);
            Assert.IsTrue(us.TestCases.Count == 2);
            Assert.AreEqual(1, us.Id);
        }

        [Test]
        public void CanCreateUserStoryWithoutParameter()
        {
            var us = UserStoryResources.Bowling.CompleteUserStory;
            Assert.IsNotNull(us);
            Assert.AreEqual(TestCaseResources.GutterGame.Title, us.Title);
            Assert.AreEqual(TestCaseResources.GutterGame.Description, us.Description);
            Assert.IsTrue(us.TestCases.Count == 3);
            Assert.AreEqual(1, us.Id);
        }

        [Test]
        public void CanFailCreateUserStoryOnlyWithTitle()
        {
            Assert.Throws(Is.TypeOf(typeof (UserStoryException)).And.Message.EqualTo(Resource.US_BUILD_FAILED),
                          () => UserStory.Builder.Title(TestCaseResources.GutterGame.Title).Build());
        }

        [Test]
        public void CanFailedCreateUserStoryOnlyWithDescription()
        {
            Assert.Throws(Is.TypeOf(typeof (UserStoryException)).And.Message.EqualTo(Resource.US_BUILD_FAILED),
                          () => UserStory.Builder.Description(TestCaseResources.GutterGame.Description).Build());
        }

        [Test]
        public void CanFailedCreateUserStoryOnlyWithId()
        {
            Assert.Throws(Is.TypeOf(typeof (UserStoryException)).And.Message.EqualTo(Resource.US_BUILD_FAILED),
                          () => UserStory.Builder.Id(TestResource.IdUserStory).Build());
        }

        [Test]
        public void CanFailedCreateUserStoryWithoutTestCase()
        {
            Assert.Throws(
                Is.TypeOf(typeof (UserStoryException)).And.Message.EqualTo(Resource.US_BUILD_FAIL_ONE_TEST_CASE),
                () => UserStory.Builder
                          .Description(TestCaseResources.GutterGame.Description)
                          .Id(TestResource.IdUserStory)
                          .Title(TestCaseResources.GutterGame.Title)
                          .Build());
        }

        [Test]
        public void CanFailedWhenCreateUserStoryWithoutParameter()
        {
            Assert.Throws(Is.TypeOf(typeof (UserStoryException)).And.Message.EqualTo(Resource.US_BUILD_FAILED),
                          () => UserStory.Builder.Build());
        }
    }
}